// import Vue from 'vue'
import { createRouter, createWebHistory } from 'vue-router'

import Login from '../views/Login.vue'
import Home from '../views/Home.vue'

const routes = [
    {
        path: '/',
        name: 'Login',
        component: Login
    },
    {
        path: '/home',
        name: 'Home',
        component: Home,
        meta: {requiresAuth: true}
    },
    {
        path: "/:pathMatch(.*)*",
        component: () => import('@/views/error/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error/401'),
        hidden: true
    },
]

const router = createRouter({
    history: createWebHistory(),
    isAddDynamicMenuRoutes: false,
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({ left: 0, top: 0 }),
    routes: routes
})

// 路由守卫
// router.beforeEach((to, from, next) => {
//     const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
//     const isAuthenticated = Vue.prototype.$auth.isAuthenticated
//
//     if (requiresAuth && !isAuthenticated) {
//         next('/')
//     } else {
//         next()
//     }
// })

export default router